<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="t" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@taglib prefix="user" uri="/WEB-INF/tags/UserDescriptor.tld"%>
<%@taglib prefix="error" uri="/WEB-INF/tags/ErrorTag.tld"%>

<t:basicTemplate pageTitle="SWIMv2 - Add Friends">


	<jsp:body>
		<h1>Add New Friends</h1>
		<div class="error-style">
			<error:errors error="${param.error}"></error:errors>
		</div>
		<h2>Add friends</h2>
    	<form name="addFriends" method="POST"
			action="./proceedFriendshipRequest">
			<input type="text" name="newFriend" size="20" /><br />
			<input type="submit" value="Submit" name="B1" />
			<input type="hidden" value="true" name="direct" />
			<t:errorAndMessage message="${message}" />
		</form>
		<h2>Friendship Requests</h2>
		
			<c:if test="${fn:length(requests) > 0}">
			<form name="friendshipRequest" action="./proceedAcceptFriend"
				method="POST">
			<c:forEach items="${requests}" var="req"> 
				<div id="see_requests">
					<a href="Profile?username=${req}"> ${req}</a>
					<br />
					<input type="radio" name="radio_${req}" value="Approve" />
					<label for="radio_${req}">Accept</label>
					<br />
			    	<input type="radio" name="radio_${req}" value="Disapprove" />
			    	<label for="radio_${req}">Refuse</label> 
			    	 
				</div> <br /> <br />
			</c:forEach>
			<input type="submit" value="Approve Requests" name="submit" /> 
			</form>
			
		</c:if>
		
		<c:if test="${fn:length(requests) == 0}">
			<h3> There are no friendship requests </h3>
			<br />
			(deal with it)
		</c:if>
		
		<h2>Suggested Friends</h2>
		
		<c:if test="${fn:length(suggestedFriends) > 0}">
		
		
			<c:forEach items="${suggestedFriends}" var="friend"> 
				<div id="see_suggested">
					<form method="POST" action="./proceedFriendshipRequest">
					 <div id="userDisplay">
					 <user:display username="${friend['username']}"
								surname="${friend['surname']}" name="${friend['name']}"
								email="${friend['email']}" category="${friend['category']}"
								image="${friend['image']}" />
					 
						<input type="hidden" value="${friend['username']}"
								name="newFriend" />
						<input type="hidden" value="false" name="direct" />
						<input type="submit" value="Add" />
					</div>	
					</form>
				</div> <br /> <br />
			</c:forEach>	
		
					
		</c:if>
		
		<c:if test="${fn:length(suggestedFriends) == 0}">
			<h3>There are no suggested Friends</h3>
			<br />
			(deal with it)
		</c:if>
    </jsp:body>
</t:basicTemplate>
